function SearchContainerItem(websearch, name, icon)
{
	this.name = name;
	this.search = websearch;
	this.icon = icon;
}
function SearchContainer(name, icon)
{
	var _searches;
	var _exclude_ids;
	
	var _status;
	var _last_time_updated;
	
	var _childs_container;
	var _parent_container;
	
	var _name;
	var _icon;
	
	function _construct(name, icon)
	{
		_name = name;
		_icon = icon;
		
		_searches = [];
		_exclude_ids = [];
		
		_childs_container = [];
		
		_parent_container = null;
	}
	
	this.getName = function() {return _name;}
	this.getIcon = function() {return _icon;}
	this.getChilds = function() {return _childs_container;}
	
	this.hasParent = function() {return (_parent_container != null)}
	this.getParent = function() {return _parent_container;}

	this.setName = function(name) {_name = name;}
	this.setIcon = function(icon) {_icon = icon;}
	this.setParentContainer = function(parent) {_parent_container = parent;}

  this.removeChildContainer = function(searchcontainer) {
    for (var i = 0; i < _childs_container.length; i++)
    {
      var c = _childs_container[i];
      if (c == searchcontainer)
      {
        _childs_container.splice(i,1);
				console.log("founded")
        break;
      }
    }
		console.log("finish")
  }
  this.remove = function() {
		if (this.hasParent())
	    _parent_container.removeChildContainer(this);

  }
	this.addSearch = function(search)
	{
		if (!(search instanceof SearchContainerItem))
		{
			this.sendError("La recherche ajoutée n'est pas de type SearchContainerItem");
			return;
		}
		
		_searches.push(search);
	}
		
	this.addContainer = function(c)
	{
		if (!(c instanceof SearchContainer))
		{
			this.sendError("Le conteneur ajouté n'est pas de type SearchContainer");
			return;
		}
		
		_childs_container.push(c);
		c.setParentContainer(this);
	};
	
	
	this.toString = function(indent)
	{
		if (typeof(indent) == "undefined")
			indent = "";

		var str = "";
		str += indent+"Name: "+_name+"\n";
		str += indent+"Icon: "+_icon+"\n";
		
		if (_childs_container.length > 0)
		{
			for (var i = 0; i < _childs_container.length; i++)
			{
				var child = _childs_container[i];
				str += "\n"+indent+"[C] "+child.getName()+"\n";
				str += child.toString(indent+"+")
			}
			
		}
		
		return str;
	};
	
	_construct(name,icon);
}

SearchContainer.$useError();
